import {KintoneRestAPIClient} from '@kintone/rest-api-client';
import {AppElementInfo} from './AppElementInfo';
class Api {
  constructor() {
    this.kintoneClient = new KintoneRestAPIClient();
  }
  getApp(appId) {
    return this.kintoneClient.app.getApp({id: appId});
  }
  getAppFields(appId) {
    return this.kintoneClient.app.getFormFields({app: appId});
  }
  getAppElementInfo(appId) {
    return new Promise((resolve, reject) =>{
      Promise.all([this.getApp(appId), this.getAppFields(appId)]).then(resp =>{
        resolve(new AppElementInfo(appId, resp[0].name, resp[1]));
      }).catch(error =>{
        reject(error);
      });
    });
  }
  getAppDatas(appId, query = '') {
    return this.kintoneClient.record.getRecords({app: appId, query: query});
  }
  updateAppRecord(appId, recordId, record) {
    return this.kintoneClient.record.updateRecord({app: appId, id: recordId, record: record});
  }
}
export default Api;